package cn.stylefeng.guns.dao;

import cn.stylefeng.guns.pojos.UserOrder;
import cn.stylefeng.guns.pojos.WorkUC;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserOrderDao extends BaseMapper<UserOrder> {

    // 查询每个学员的订单量
    @Select("SELECT u.id, u.`t_username`,COUNT(*) count FROM tb_order o,tb_user u WHERE o.t_user_guid = u.`id` AND u.`id`=#{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "t_username",property = "tUsername"),
            @Result(column = "count",property = "count")
    })
    UserOrder userOrderCount(@Param("id") Integer id);

    // 查询用户的作品量
    @Select("SELECT\n" +
            "\tu.id,u.t_username,count(*) count\n" +
            "FROM\n" +
            "\ttb_user u,\n" +
            "\ttb_works w\n" +
            "WHERE\n" +
            "\tw.recordguid=u.row_guid AND u.id=#{id}")
    UserOrder userWorkCount(@Param("id") Integer id);

    // 查询用户的课程试听量
    @Select("SELECT u.id, u.t_username, count(*) count\n" +
            "FROM tb_user u, tb_course c, tb_try_course tc\n" +
            "WHERE tc.user_guid=u.group_guid AND c.group_guid=tc.course_guid AND u.id=#{id}")
    UserOrder userCourseCount(@Param("id") Integer id);

}
